package com.njtech.smartuniversity.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.njtech.smartuniversity.bean.AreaBean;
import com.njtech.smartuniversity.bean.AreaBeanExample;
import com.njtech.smartuniversity.config.security.JwtTokenUtil;
import com.njtech.smartuniversity.dao.AreaBeanMapper;
import com.njtech.smartuniversity.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by ritchie on 6/25/18
 */

@Service
public class AreaServiceImpl implements AreaService {

    @Autowired
    AreaBeanMapper mAreaBeanMapper;

    @Override
    public int update(AreaBean areaBean) {
        Integer id = areaBean.getId();
        return  mAreaBeanMapper.update(areaBean);
    }

    @Override
    public List<AreaBean> getAllUsers() {
        AreaBeanExample areaBeanExample = new AreaBeanExample();
        AreaBeanExample.Criteria criteria =areaBeanExample.createCriteria() ;
        criteria.andIdIsNotNull();
        return mAreaBeanMapper.selectByExample(areaBeanExample);
    }

    @Override
    public PageInfo<AreaBean> getAreasByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<AreaBean> list = getAllUsers();//这个查询会分页
        return new PageInfo<>(list);
    }


    @Override
    public boolean deleteById(int id) {
        int result = mAreaBeanMapper.delete(id);
        return result != 0;
    }

    @Override
    public int addUser(AreaBean AreaBean) {
        return mAreaBeanMapper.insert(AreaBean);
    }




}
